'use strict';
// 云函数register的代码
const uniID = require('uni-id')
exports.main = async function(event, context) {
	const {
		data,
		action
	} = event
	const actions = {
		register: async (event, context) => {
			const {
				username,
				password
			} = data
			const res = await uniID.register({
				username,
				password
			})
			return res
		},
		login: async (event, context) => {
			const {
				username,
				password
			} = data
			const res = await uniID.login({
				username,
				password
			})
			return res
		},
		logout: async (event, context) => {
			const res = await uniID.logout(event.uniIdToken)
			return res
		},
		checkLogin: async (event, context) => {
			const res = await uniID.checkToken(event.uniIdToken)
			return res
		}
	}

	return actions[action](event, context)
}
